package logic

import (
	"context"
	"course_srv/course"
	"course_srv/internal/svc"
	"course_srv/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddCommentLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCommentLogic {
	return &AddCommentLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddCommentLogic) AddComment(in *course.AddCommentRequest) (*course.AddCommentResponse, error) {
	c := mysql.Comment{
		UserId:   int(in.UserId),
		CourseId: int(in.CourseId),
		Content:  in.Content,
		Score:    int(in.S),
	}
	err := c.AddComment()
	if err != nil {
		logx.Error("评价失败")
		return nil, err
	}
	return &course.AddCommentResponse{UserId: int32(c.UserId)}, nil
}
